]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
network/status: Split out NMMenuItem base class
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 2 Aug 2022 11:41:13 +0000 (13:41 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 10 Aug 2022 12:17:19 +0000 (12:17 +0000)
The class only provides the GObject properties that are currently
defined by NMConnectionItem, plus a way to set the active connection
that should be used for the item's :is-active state.

Its sole purpose is to provide a shared base for both device- and
connection items, and to have that base be a GObject so we can
start linking properties via bindings rather than manual fiddling.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2407>

js/ui/status/network.js

index a4ed4a4e6ed9b636f0a107cdad79035c9b7c1a27..394fd074e7dd18d0e325ca0977c23e65f9ff48e5 100644 (file)
@@ -148,7 +148,7 @@ class ItemSorter {
     }
 }
 
-const NMConnectionItem = GObject.registerClass({
+const NMMenuItem = GObject.registerClass({
     Properties: {
         'radio-mode': GObject.ParamSpec.boolean('radio-mode', '', '',
             GObject.ParamFlags.READWRITE,
@@ -163,7 +163,45 @@ const NMConnectionItem = GObject.registerClass({
             GObject.ParamFlags.READWRITE,
             ''),
     },
-}, class NMConnectionItem extends PopupMenu.PopupBaseMenuItem {
+}, class NMMenuItem extends PopupMenu.PopupBaseMenuItem {
+    get state() {
+        return this._activeConnection?.state ??
+            NM.ActiveConnectionState.DEACTIVATED;
+    }
+
+    get is_active() {
+        return this.state <= NM.ActiveConnectionState.ACTIVATED;
+    }
+
+    activate() {
+        super.activate(Clutter.get_current_event());
+    }
+
+    _activeConnectionStateChanged() {
+        this.notify('is-active');
+        this.notify('icon-name');
+
+        this._sync();
+    }
+
+    _setActiveConnection(activeConnection) {
+        this._activeConnection?.disconnectObject(this);
+
+        this._activeConnection = activeConnection;
+
+        this._activeConnection?.connectObject(
+            'notify::state', () => this._activeConnectionStateChanged(),
+            this);
+        this._activeConnectionStateChanged();
+    }
+
+    _sync() {
+        // Overridden by subclasses
+    }
+});
+
+const NMConnectionItem = GObject.registerClass(
+class NMConnectionItem extends NMMenuItem {
     constructor(section, connection) {
         super();
 
@@ -203,15 +241,6 @@ const NMConnectionItem = GObject.registerClass({
         return this._connection.get_id();
     }
 
-    get state() {
-        return this._activeConnection?.state ??
-            NM.ActiveConnectionState.DEACTIVATED;
-    }
-
-    get is_active() {
-        return this.state <= NM.ActiveConnectionState.ACTIVATED;
-    }
-
     updateForConnection(connection) {
         // connection should always be the same object
         // (and object path) as this._connection, but
@@ -249,7 +278,7 @@ const NMConnectionItem = GObject.registerClass({
     }
 
     activate() {
-        super.activate(Clutter.get_current_event());
+        super.activate();
 
         if (this.radio_mode && this._activeConnection != null)
             return; // only activate in radio mode
@@ -262,20 +291,8 @@ const NMConnectionItem = GObject.registerClass({
         this._sync();
     }
 
-    _connectionStateChanged(_ac, _newstate, _reason) {
-        this.notify('is-active');
-        this._sync();
-    }
-
-    setActiveConnection(activeConnection) {
-        this._activeConnection?.disconnectObject(this);
-
-        this._activeConnection = activeConnection;
-
-        this._activeConnection?.connectObject('notify::state',
-            this._connectionStateChanged.bind(this), this);
-
-        this._sync();
+    setActiveConnection(connection) {
+        this._setActiveConnection(connection);
     }
 });
 
@@ -1498,7 +1515,7 @@ const NMVpnConnectionItem = GObject.registerClass({
             this.remove_accessible_state(Atk.StateType.CHECKED);
     }
 
-    _connectionStateChanged() {
+    _activeConnectionStateChanged() {
         const state = this._activeConnection?.get_state();
         const reason = this._activeConnection?.get_state_reason();
 
@@ -1507,8 +1524,7 @@ const NMVpnConnectionItem = GObject.registerClass({
             reason !== NM.ActiveConnectionStateReason.USER_DISCONNECTED)
             this.emit('activation-failed');
 
-        this.notify('icon-name');
-        super._connectionStateChanged();
+        super._activeConnectionStateChanged();
     }
 
     get icon_name() {